package com.sop.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sop.model.PeopleInfo;
import com.sop.model.WatchArrangements;
import com.sop.model.vo.PeopleInfoVo;
import com.sop.model.vo.WatchArrangementsVo;
import com.sop.service.WatchArrangementsService;
import common.base.GridPage;


@Controller
@RequestMapping("watchArrangements")
public class WatchArrangementsController {

	@Autowired
	private  WatchArrangementsService  watchArrangementsService;
	
	@ResponseBody
	@RequestMapping("/findWeek")
	public List<Date>  findWeek(Date checkDate){
		return watchArrangementsService.findWeek(checkDate);
	}
	
	/**
	 * 排班调换
	 * @param watchArrangementsVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/changeArrangement")
	public boolean changeArrangement(WatchArrangementsVo  watchArrangementsVo){
		try{
		return watchArrangementsService.changeArrangement(watchArrangementsVo);
		}catch(Exception e){
			return false;
		}
	}
	
	/**
	 * 分页加高级搜索
	 * @param watchArrangementsVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findByPages")
	public GridPage<WatchArrangements>  findByPages(WatchArrangementsVo  watchArrangementsVo){
		return  watchArrangementsService.findPagerBySearchVo(watchArrangementsVo);
	}
	/**
	 * 获取all
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findAll")
	public List<WatchArrangements>  findAll(){
		List<WatchArrangements> watchArrangementsList = watchArrangementsService.findAll();
		return watchArrangementsList;
	}
	
	/**
	 * 获取指定月份的值班表
	 * @param watchArrangementsVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findByMonth")
	public List<WatchArrangementsVo>  findByMonth(WatchArrangementsVo watchArrangementsVo){
		List<WatchArrangementsVo> watchArrangementsList = watchArrangementsService.findByMonth(watchArrangementsVo);
		return watchArrangementsList;
	}
	
	/**
	 * 获取当天的安排
	 * 分早，中， 晚班
	 * @param watchArrangementsVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getDayArrange")
	public WatchArrangementsVo  getDayArrange(WatchArrangementsVo watchArrangementsVo){
		WatchArrangementsVo watchArrangements = watchArrangementsService.getDayArrange(watchArrangementsVo.getCheckDate());
		return watchArrangements;
	}
	
	/**
	 * 获取指定日期所在星期安排
	 * @param watchArrangementsVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findWeekByDate")
	public List<WatchArrangementsVo>  findWeekByDate(WatchArrangementsVo watchArrangementsVo){
		List<WatchArrangementsVo> watchArrangementsList = watchArrangementsService.findWeekByDate(watchArrangementsVo);
		return watchArrangementsList;
	}
	
	/**
	 * 获取当天值班安排
	 * 所有安排在一个list
	 * @param watchArrangementsVo
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/findByDate")
	public List<WatchArrangements>  findByDate(WatchArrangementsVo watchArrangementsVo){
		List<WatchArrangements> watchArrangementsList = watchArrangementsService.findByDate(watchArrangementsVo.getCheckDate());
		for(WatchArrangements watchArrangements:watchArrangementsList){
			System.out.println(watchArrangements.getTime());
		}
		
		return watchArrangementsList;
	}
	
	/**
	 * 新增
	 * @param info
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/add")
	public WatchArrangements  add(WatchArrangements info){
		WatchArrangements watchArrangements = watchArrangementsService.add(info);
		return watchArrangements;
	}
	
	/**
	 * 多个新增
	 * @param info
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/addBatch")
	public List<WatchArrangements>  addBatch(WatchArrangementsVo info){
		for(WatchArrangements  watchArrangements:info.getNormal()){
		 watchArrangementsService.add(watchArrangements);
		}
		return info.getNormal();
	}
	
	
	@ResponseBody
	@RequestMapping("/update")
	public WatchArrangements  update(WatchArrangements info){
		WatchArrangements watchArrangements = watchArrangementsService.update(info);
		return watchArrangements;
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public boolean  delete(Integer id){
		watchArrangementsService.delete(id);
		return true;
	}
}
